import Vue from 'vue';
import Router from 'vue-router';

Vue.use(Router);

const routes = [
  {
    path: '*',
    redirect: '/index'
  },
  {
    name: 'index',
    component: () => import('./view/index'),
    meta: {
      title: '首页'
    }
  },
  {
    name: 'stateNo',
    component: () => import('./view/state/state_no.vue'),
    meta: {
      title: '未注册'
    }
  },
  {
    name: 'stateOpen',
    component: () => import('./view/state/state_opened.vue'),
    meta: {
      title: '已注册'
    }
  },
  {
    name: 'register',
    component: () => import('./view/register/register.vue'),
    meta: {
      title: '用户注册'
    }
  },
  {
    name: 'registered',
    component: () => import('./view/register/register_ed.vue'),
    meta: {
      title: '注册成功-待审核'
    }
  },
  {
    name: 'registerFail',
    component: () => import('./view/register/register_fail.vue'),
    meta: {
      title: '注册失败'
    }
  },
  {
    name: 'registerSuccess',
    component: () => import('./view/register/register_success.vue'),
    meta: {
      title: '注册成功-待签署'
    }
  },
  {
    name: 'uploadImages',
    component: () => import('./view/uploadImages/index'),
    meta: {
      title: '上传图片'
    }
  },
  {
    name: 'reconciliation',
    component: () => import('./view/reconciliation/index'),
    meta: {
      title: '今日收款'
    }
  },
  {
    name: 'collectionCode',
    component: () => import('./view/collectionCode/index'),
    meta: {
      title: '收款码收款'
    }
  },
  {
    name: 'setAmount',
    component: () => import('./view/setAmount/index'),
    meta: {
      title: '设置金额'
    }
  },
  {
    name: 'payment',
    component: () => import('./view/payment/index'),
    meta: {
      title: '付款'
    }
  },
  {
    name: 'statement',
    component: () => import('./view/statement/index'),
    meta: {
      title: '对账单'
    }
  },
  {
    name: 'collectionRecord',
    component: () => import('./view/collectionRecord/index'),
    meta: {
      title: '收款记录'
    }
  },
  {
    name: 'collectionRecordCopy',
    component: () => import('./view/collectionRecordCopy/index'),
    meta: {
      title: '收款记录'
    }
  },
  {
    name: 'collectionToday',
    component: () => import('./view/collectionToday/index'),
    meta: {
      title: '当日收款详情'
    }
  },
  {
    name: 'dateQuery',
    component: () => import('./view/dateQuery/index'),
    meta: {
      title: '自定义查询'
    }
  },
  {
    name: 'waitResult',
    component: () => import('./view/waitResult/index'),
    meta: {
      title: '聚合支付'
    }
  },
  {
    name: 'calendar',
    component: () => import('./view/calendar/index'),
    meta: {
      title: '对账日历'
    }
  },
  {
    name: 'rules',
    component: () => import('./view/blueAction/rules.vue'),
    meta: {
      title: '活动规则'
    }
  },
  {
    name: 'actionDetail',
    component: () => import('./view/blueAction/actionDetail.vue'),
    meta: {
      title: '蓝海行动活动详情'
    }
  }
];

// add route path
routes.forEach(route => {
  route.path = route.path || '/' + (route.name || '');
});

const router = new Router({ routes });

router.beforeEach((to, from, next) => {
  const title = to.meta && to.meta.title;
  if (title) {
    document.title = title;
  }
  next();
});

export {
  router
};
